import React, { Component } from 'react';
import TableFilter from './TableFilter';
import CustomTable from './CustomTable';
import Api from '../../../../Api/Api';
import Ajax from '../../../../Ajax';

export default class AuthorityTable extends Component {
  static displayName = 'AuthorityTable';

  static propTypes = {};

  static defaultProps = {};

  constructor(props) {
    super(props);
    this.state = {
      dataSource: [],
      total: 0,

    };
  }
  componentDidMount() {
    var url = Api.getAllUsers();
    Ajax.get(url)
      .then((res) => {
        // console.log(res.data)
        if (res.data.code) {
          this.setState({
            dataSource: res.data.data,
            total: res.data.total
          })
        } else {
          this.setState({
            dataSource: [],
            total: 0
          })
        }
      })
  }
  // 查询后调用
  changeDataSource = (array, total) => {
    this.setState({
      dataSource: array,
      total: total
    })
    // console.log(array, total)
  }

  render() {
    const { dataSource, total } = this.state;
    return (
      <div style={styles.container}>
        <TableFilter 
        changeDataSource={this.changeDataSource}
        />
        <CustomTable 
          dataSource={dataSource}
          total={total}
          changeDataSource={this.changeDataSource}
        />
        
      </div>
    );
  }
}

const styles = {};
